//
//  UIBarButtonItem+LXQNavigation.m
//  KaKaFastCarDriver
//
//  Created by LiXiqing on 16/11/3.
//  Copyright © 2016年 LiXiQing. All rights reserved.
//

#import "UIBarButtonItem+LXQNavigation.h"

@implementation UIBarButtonItem (LXQNavigation)
+ (instancetype)itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
//    button.size = button.currentBackgroundImage.size;
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[self alloc] initWithCustomView:button];
}

+(instancetype)itemWithTitle:(NSString *)title target:(id)target action:(SEL)action
{
        UIButton *moreBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [moreBtn setFrame:CGRectMake(0,5,80,44)];
        [moreBtn setBackgroundColor:[UIColor clearColor]];
        [moreBtn setTitle:title forState:UIControlStateNormal];
        [moreBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [moreBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [moreBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
//        [moreBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)];
        [moreBtn sizeToFit];
        [moreBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[self alloc]initWithCustomView:moreBtn];
}
+ (instancetype)itemLeftWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    ////    button.size = button.currentBackgroundImage.size;
    
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
//    button.size = CGSizeMake(70, 30);
    // 让按钮内部的所有内容左对齐
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    
    // 让按钮的内容往左边偏移10
    button.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 40);
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[self alloc] initWithCustomView:button];
}
@end
